package com.unittec.zk.provider.utils;

import java.util.Random;

/**
 * @description 生成验证码Util
 * @author JY
 * @date 2019/08/08
 */
public class GenerateCodeUtil {

    /**
     * 根据num生成随机数字
     * 
     * @return
     */
    public static String getFourRandomNumber(int num) {
        String code = "";
        Random random = new Random();
        for (int i = 0; i < num; i++) {
            int number = Math.abs(random.nextInt()) % 10;
            code += number;
        }
        return code;
    }

    /**
     * 随机数
     * 
     * @param place
     *            定义随机数的位数
     */
    public static String randomGen(int place) {
        String base = "qwertyuioplkjhgfdsazxcvbnmQAZWSXEDCRFVTGBYHNUJMIKLOP0123456789";
        StringBuffer sb = new StringBuffer();
        Random rd = new Random();
        for (int i = 0; i < place; i++) {
            sb.append(base.charAt(rd.nextInt(base.length())));
        }
        return sb.toString();
    }

}
